package com.woniuxy.service.impl;

import com.woniuxy.dao.ExamDao;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Training;
import com.woniuxy.entity.dto.ExamDto;
import com.woniuxy.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：jojo
 * @Date：2022/3/16 11:30
 * @Description :TODO
 */
@Service
public class ExamServiceImpl implements ExamService {
    @Autowired(required = false)
    ExamDao examDao;

    @Override
    public ResponseEntity findAll(int id) {
        List<ExamDto> examDtos = new ArrayList();
        List<Training> trainings = examDao.findT(id);
        System.out.println(trainings + "培训详情");
        for (Training training : trainings) {
            ExamDto examDto = new ExamDto();
            String score = examDao.findS(id, training.getId());
            String status = examDao.findStatus(id,training.getId());
            int topicid = examDao.findTopicid(training.getId(), id);
            examDto.setTraining(training);
            examDto.setScore(score);
            examDto.setStatus(status);
            examDto.setTopicid(topicid);
            examDtos.add(examDto);
        }
        return ResponseEntity.success("考试查询", examDtos);
    }

    @Override
    public ResponseEntity findStatus(int id) {
        List<Integer> trainingids = examDao.findP(id);
        for (Integer tid : trainingids) {
            examDao.setStatus(id, tid);
        }
        return ResponseEntity.success("更改状态");
    }
}
